package com.aerozhonghuan.logisticsmall.modules.sort;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.aerozhonghuan.logisticsmall.R;

import java.util.ArrayList;

/**
 * Created by ChenLin on 2019/5/22 15:03.Email&WeChat:7877409@163.com
 */
public class ProductBrandAdapter extends BaseAdapter {

    ArrayList<String> strList = new ArrayList<String>();
    private Context mContext;
    private int mClickPosition = -1;

    public ProductBrandAdapter(Context context) {
        mContext = context;
    }

    public void setData(ArrayList<String> list, int clickPosition) {
        strList = list;
        mClickPosition = clickPosition;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return strList.size();
    }

    @Override
    public Object getItem(int position) {
        return strList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup arg2) {
        HolderView holderView = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext)
                    .inflate(R.layout.list_item_textview, null);
            holderView = new HolderView();
            holderView.title = (TextView) convertView.findViewById(R.id.title);
            holderView.itemSelected = (TextView) convertView.findViewById(R.id.item_selected);
            convertView.setTag(holderView);
        } else {
            holderView = (HolderView) convertView.getTag();
        }
        String itemSelected = strList.get(position);
        holderView.title.setText(itemSelected);
        Log.d("community2", "clickPosition  position=" + position);
        if (mClickPosition == position) {
            holderView.itemSelected.setVisibility(View.VISIBLE);
            holderView.title.setTextColor(mContext.getResources().getColor(R.color.red));
        } else {
            holderView.itemSelected.setVisibility(View.INVISIBLE);
            holderView.title.setTextColor(mContext.getResources().getColor(R.color.tab_black));
        }
        return convertView;
    }

    class HolderView {
        TextView title;
        TextView itemSelected;
    }
}
